package com.d0327.homework;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Random;

public class StudentTest implements Comparator<Student1> {
    @Override
    public int compare(Student1 o1, Student1 o2) {
        if (o1.getScore() >= o2.getScore()) {
            return 1;
        } else if (o1.getScore() < o2.getScore()) {
            return -1;
        } else {
            if (o1.getId()<o2.getId()){
                return 1;
            }else if (o1.getId()>o2.getId()){
                return -1;
            }else {
                return 0;
            }
        }
    }
    public static void main(String[] args) {
        Student1[] students=new Student1[68];
        Random random = new Random();
        for (int i = 0; i <68 ; i++) {
            students[i]=((new Student1(180200+(i+1),(i+1) +"\t",random.nextInt(50)+51)));
        }
        Arrays.sort(students,new StudentTest());
        for (int i=students.length-1;i>0;i--) {
            System.out.println("学号："+students[i].getId()+", \t 姓名：同学"+students[i].getName()+", \t 成绩："+students[i].getScore());
        }
    }
}
